<?php
	header("Content-type:text/html; charset=utf-8");
	$db = mysql_connect("127.0.0.1","root","");
	mysql_select_db("hdedu_cms");
	$language = "set names utf8";
	mysql_query($language);
	$res = "select * from hd_news as n join hd_news_data as nd on n.id=nd.nid join hd_category as c on c.catid=n.catid";
	$result = mysql_query($res);
	$rows = array();
	while($row = @mysql_fetch_assoc($result)){
		$rows[] = $row;
	}
	$htmlRootDir = "html";    //静态生成的根目录; 
	foreach($rows as $field){
		$time = getdate($field["addtime"]);			//获得到时间的数组格式；
		$search = array('{htmldir}',"{y}","{m}",'{d}','{nid}');
		$replace = array($field['htmldir'],$time['year'],$time['mon'],$time['mday'],$field['id']);
		$htmlFile = $htmlRootDir.'/'.str_ireplace($search,$replace,$field['archtml']);  //生成路径:根目录/年月日/文件名；
		$htmlDir = dirname($htmlFile);
		is_dir($htmlDir) || mkdir($htmlDir,0777,true);
		ob_start();
		include "tpl/arc.html";            //调入使用模板；
		$content = ob_get_clean();
		file_put_contents($htmlFile,$content);  //
	}
?>